package com.testfileupload.uploadimg.design.single;

/**
 * 静态内部类实现
 * 静态内部在类加载时不会实例化，
 * 类的静态属性只会在第一次加载的时候初始化，jvm保证了线程的安全，
 * 别的线程不会进入
 */
public class SingleModel6 {
    public static void main(String[] args) {
        Single5 instence = Single5.getInstence();
        Single5 instence1 = Single5.getInstence();
        System.out.println(instence);
        System.out.println(instence1);
        System.out.println(instence.equals(instence1));
        System.out.println(instence == instence1);
    }
}

class Single5 {

    private static volatile Single5 single;

    /**
     * 构造私有化，不能new
     */
    private Single5() {
    }

    private static class Singleton {
        private final static Single5 INSTENCE = new Single5();
    }

    /**
     * 提供共有静态方法
     *
     * @return
     */
    public static Single5 getInstence() {
        Single5 instence = Singleton.INSTENCE;
        return instence;
    }

}
